from os import path

import os


def get_filenames(dirpath, filenames):
    # 绝对路径
    if not path.isabs(dirpath):
        dirpath = path.abspath(dirpath)
    print("文件夹路径:", dirpath)

    for (pathname, dirs, files) in os.walk(dirpath):

        if files:  # 文件,则添加进列表

            for f in files:
                filenames.append(path.join(pathname, f))

            if dirs:  # 目录,递归获取

                for dir_ in dirs:
                    get_filenames(path.join(pathname, dir_), filenames)


if __name__ == '__main__':
    path1 = "C:\\Users\\40138\\Desktop\\gdisk"
    filenames = []
    get_filenames(path1, filenames)
    print(filenames)
    li = []
    for file in filenames:
        a = open(file)
        readLines = a.readlines()
        for i in readLines:
            li.append(i)
        a.close()
    path2 = "D:\\rclone.conf"
    c = open(path2, "a")
    for line in li:
        c.write(line)
